package com.ff.neuropp.controller;


import com.ff.neuropp.domain.SystemLog;
import com.ff.neuropp.service.SystemLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/systemlog")
@Api(value = "系统日志controller", tags = {"系统日志接口"})
public class SystemLogController {

    @Resource
    private SystemLogService systemLogService;

    @GetMapping("/search")
    @ApiOperation(value = "搜索日志", notes = "搜索日志")
    public Map<String, Object> searchLogs(@ApiParam(required = false, value = "开始时间") @RequestParam(required = false) String beginTime,
                                          @ApiParam(required = false, value = "结束时间") @RequestParam(required = false) String endTime,
                                          @ApiParam(required = false, value = "日志用户") @RequestParam(required = false) String account) {

        Map<String, Object> result = new HashMap<>();
        Map<String, Object> param = new HashMap<>();
        param.put("GT_id", 0);
        if (null != beginTime && beginTime.length() > 0) {
            param.put("GT_create_date", beginTime);
        }
        if (null != endTime && endTime.length() > 0) {
            param.put("LT_create_date", endTime);
        }
        if (null != account && account.length() > 0) {
            param.put("LIKE_logAccount", account);
        }
        List<SystemLog> list = systemLogService.findList(param);
        //List<SystemLog> list = systemLogService.searchSystemLogsByTag(beginTime, endTime, account);
        if (null != list && list.size() > 0) {

            result.put("data", list);
            result.put("total", Integer.valueOf(list.size()));//总记录数
            result.put("code", 10000);
            result.put("message", "搜索日志完成");
        } else {
            result.put("code", 10001);
            result.put("message", "没有日志数据");
        }

        return result;
    }
}
